using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Husb.Data;
using Husb.Util;
using CentralOffice.MyTable.Data;
using CentralOffice.MyTable.BusinessActions;

using ViewEmailTable = CentralOffice.MyTable.Data.EmailDataSet.View_EmailDataTable;
using ViewEmailRow = CentralOffice.MyTable.Data.EmailDataSet.View_EmailRow;
using System.Collections.Specialized;
namespace CentralOffice.WebClient.desktop.email
{
    public partial class news : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //odsEmail.SelectParameters["whereClause"].DefaultValue = " ToId='" + ApplicationContext.ActualUserId + "' and ReadFlag='0' and DeleteFlag<='1' and SendFlag='1'";
            }
        }

        protected void odsMail_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            IOrderedDictionary parameters = e.InputParameters;
            parameters["whereClause"] = " ToId='" + ApplicationContext.ActualUserId + "' and ReadFlag='0' and DeleteFlag<='1' and SendFlag='1'";
            
        }


        protected void gv_Email_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ViewEmailRow vrow = ((DataRowView)e.Row.DataItem).Row as ViewEmailRow;
                if (vrow.ReadFlag == "0")
                {
                    Image img = new Image();
                    img.ImageUrl = "~/images/email_new.gif";
                    e.Row.Cells[2].Controls.Add(img);
                }
                if (!vrow.IsSizeNull())
                {
                    if (vrow.Size >= 1024)
                    {
                        e.Row.Cells[5].Text = (Math.Round(Convert.ToDecimal(vrow.Size / 1024), 2)).ToString() + "M";
                    }
                    else if (vrow.Size > 0)
                    {
                        e.Row.Cells[5].Text = vrow.Size.ToString() + "K";
                    }
                }
                //GetAttachmentName
                string strAttach = "";
                if (!vrow.IsAttachmentNameNull() && !String.IsNullOrEmpty(vrow.AttachmentName))
                {
                    string[] strAttachList = vrow.AttachmentName.Split('|');
                    
                    for (int i = 0; i < strAttachList.Length; i++)
                    {
                        strAttach += SiteUtil.GetAttachmentName(strAttachList[i]) + ",";
                    }
                    strAttach = strAttach.Substring(0, strAttach.Length - 1);
                }
                e.Row.Cells[3].Text = strAttach;
            }
        }
    }
}
